package cn.tedu.charging.order.quartz;

import org.quartz.*;

import java.util.Date;
import java.util.UUID;

/**
 * 设备检查调度执行器
 */
public class SchedulerExecutor {

    public static void scheduleCheckJob(String orderNo,Integer gunId) throws SchedulerException {
           //1.创建JobDetail对象
           JobDetail jobDetail = JobBuilder.newJob(DeviceCheckJob.class)
                .withIdentity("DeviceCheckJob:" + UUID.randomUUID(),
                        "device_check_job_group")
                   .usingJobData("orderNo",orderNo)
                   .usingJobData("gunId",gunId)
                .build();
           //2.创建Trigger对象
           long currentTime = System.currentTimeMillis();
           Date triggerStartAt = new Date(currentTime+1*60*1000);
           Trigger jobTrigger = TriggerBuilder.newTrigger()
                   .withIdentity("DeviceCheckTrigger:"+UUID.randomUUID(), "group1") //唯一标识
                   .startAt(triggerStartAt).build();
           //3.基于Scheduler调度任务
           //3.1获取Scheduler对象(从Spring容器中获取)
           Scheduler scheduler =
                ApplicationContextProvider.getContext().getBean(Scheduler.class);
           //3.2执行任务调度
           scheduler.scheduleJob(jobDetail,jobTrigger);
    }
}
